/**
 * @File SegmentController.java
 * @author Nupur Dixit
 * @Version 1.0
 * @Date April 26, 2013
 * 
 * Copyright (c) 2011 EdRP, Dayalbagh Educational Institute.
 * All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * Redistributions of source code must retain the above copyright
 * notice, this  list of conditions and the following disclaimer.
 *
 * Redistribution in binary form must reproducuce the above copyright
 * notice, this list of conditions and the following disclaimer in
 * the documentation and/or other materials provided with the
 * distribution.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL ETRG OR ITS CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Contributors: Members of EdRP, Dayalbagh Educational Institute
 */
package in.ac.dei.edrp.generalLedger.segment;

import flex.messaging.FlexContext;
import flex.messaging.FlexSession;

import in.ac.dei.edrp.generalLedger.assetRegister.AssetBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

@Controller
public class SegmentController extends MultiActionController{

	@Autowired
	@Qualifier("SegmentDaoImpl")
	private SegmentDao segmentDao;
	
	public List<SegmentInfoBean> getColumns(String groupCode){		
		FlexSession session = FlexContext.getFlexSession();				
		SegmentInfoBean input = new SegmentInfoBean();
		input.setUniversityCode((String) session.getAttribute("universityCode"));
		input.setGroupCode(groupCode);
		List<SegmentInfoBean> columnList = new ArrayList<SegmentInfoBean>();
		columnList = segmentDao.getColumns(input);	
		return columnList;
	}
	
	public List<SegmentInfoBean> getValueSet(){		
		FlexSession session = FlexContext.getFlexSession();				
		SegmentInfoBean input = new SegmentInfoBean();
		input.setUniversityCode((String) session.getAttribute("universityCode"));		
		List<SegmentInfoBean> valueSetList = new ArrayList<SegmentInfoBean>();
		valueSetList = segmentDao.getValueSet(input);	
		return valueSetList;
	}
	
	public String setSegmentDetails(Map<String,Object> mapInput){
		String result="false";
		try {	
			FlexSession session = FlexContext.getFlexSession();		
			String univCode = (String) session.getAttribute("universityCode");
			SegmentInfoBean input = new SegmentInfoBean();
			input.setName((String) mapInput.get("name"));
			input.setTitle((String) mapInput.get("title"));
			input.setSequenceNo((String) mapInput.get("sequence"));
			input.setColumn((String) mapInput.get("column"));
			input.setValueSetId((String) mapInput.get("valueSet"));			
			input.setCreatorId((String) session.getAttribute("userId"));
			input.setModifierId((String) session.getAttribute("userId"));
			input.setUniversityCode(univCode);					
			result = segmentDao.setSegment(input);
							
		} catch (Exception e) {
			result="false";
			e.printStackTrace();
			logger.error("Error inside setSegmentDetails method of SegmentController Class : ",e);
		}
		return result;
	}
	
}
